from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.template import loader

from .models import UserManager


# Create your views here.
def index(req):
    num = 10
    student = {'name': '张三', 'age': 20, 'sex': '男'}
    return render(req, 'usermanager/userindex.html', locals())
    # res = loader.get_template('usermanager/userIndex.html')
    # result = res.render(num, student)
    # return HttpResponse(req, result)


def list(req):
    # users = UserManager.objects.all()
    # res = loader.get_template('usermanager/userlist.html')
    # context = res.render({'users': users})
    # return HttpResponse(context)
    # return render(req, 'usermanager/userlist.html', {})
    users = UserManager.objects.all()
    context = {'users': users}
    return render(req, 'usermanager/userlist.html', context)


def detail(req, id):
    users = UserManager.objects.all()
    print(users)
    user = UserManager.objects.get(id=id)
    print(user)
    context = {'user': user}
    return render(req, 'usermanager/userdetall.html', context)


def get_word(req):
    context = {}
    return render(req, 'usermanager/shiyan.html', context)
